﻿@namespace AntSK.Pages.AppPage
@using AntSK.Domain.Repositories
@using AntSK.Models
@using AntSK.Domain.Domain.Model.Enum
@page "/App/Add"
@page "/App/Add/{AppId}"
@using AntSK.Services.Auth
@using AntSK.Components

@inherits AuthComponentBase

<PageContainer Title="新增应用">
    <ChildContent>
        <Card>
            <Form Model="@_appModel"
                  Style="margin-top: 8px;"
                  OnFinish="HandleSubmit">
                <FormItem Label="应用名称" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Input Placeholder="请输入应用名称" @bind-Value="@context.Name" />
                </FormItem>
                <FormItem Label="图标" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    @* <Input Placeholder="请输入图标" @bind-Value="@context.Icon" />
                    <a href="https://antblazor.com/zh-CN/components/icon" target="_blank">图标库</a> *@
                    <IconPicker @bind-Value="@context.Icon"></IconPicker>
                </FormItem>
                <FormItem Label="类型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <RadioGroup @bind-Value="context.Type" OnChange="OnAppTypeChange" TValue="string">
                        <Radio RadioButton Value="@AppType.chat.ToString()">会话应用</Radio>
                        <Radio RadioButton Value="@AppType.kms.ToString()">知识库</Radio>
                        <Radio RadioButton Value="@AppType.img.ToString()">做图应用</Radio>
                    </RadioGroup>
                </FormItem>
                <FormItem Label="描述" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Input Placeholder="请输入描述" @bind-Value="@context.Describe" />
                </FormItem>

                <FormItem Label="会话模型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Select DataSource="@_chatList"
                            @bind-Value="@context.ChatModelID"
                            ValueProperty="c=>c.Id"
                            LabelProperty="c=>'【'+c.AIType.ToString()+'】'+c.ModelDescription">
                    </Select>
                    <Button Type="@ButtonType.Link" OnClick="NavigateModelList">去创建</Button>
                </FormItem>
                @if (@context.Type != AppType.img.ToString())
                {
                    <FormItem Label="向量模型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select DataSource="@_embedingList"
                                @bind-Value="@context.EmbeddingModelID"
                                ValueProperty="c=>c.Id"
                                LabelProperty="c=>'【'+c.AIType.ToString()+'】'+c.ModelDescription">
                        </Select>
                        <Button Type="@ButtonType.Link" OnClick="NavigateModelList">去创建</Button>
                    </FormItem>
                    <FormItem Label="提示词" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <TextArea MinRows="4" Placeholder="请输入角色信息" @bind-Value="@context.Prompt" />
                    </FormItem>
                    <FormItem Label="温度系数" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <span>更确定</span>
                        <Slider TValue="double" Style="display: inline-block;width: 300px; " Min="0" Max="100" DefaultValue="70" @bind-Value="@context.Temperature" />
                        <span>更发散</span>
                    </FormItem>
                }

                else              
                {
                    <FormItem Label="图片模型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select DataSource="@_imageList"
                                @bind-Value="@context.ImageModelID"
                                ValueProperty="c=>c.Id"
                                LabelProperty="c=>'【'+c.AIType.ToString()+'】'+c.ModelDescription">
                        </Select>
                        <Button Type="@ButtonType.Link" OnClick="NavigateModelList">去创建</Button>
                    </FormItem>
                }
                @if (@context.Type == AppType.chat.ToString())
                {
                    <FormItem Label="API插件列表" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select Mode="multiple"
                                @bind-Values="apiIds"
                                Placeholder="选择API插件, 选择后会开启自动调用"
                                TItemValue="string"
                                TItem="string"
                                Size="@AntSizeLDSType.Default">
                            <SelectOptions>
                                @foreach (var api in _apiList)
                                {
                                    <SelectOption TItem="string" TItemValue="string" Value="@api.Id" Label="@(api.Name+"-"+api.Describe)" />
                                }
                            </SelectOptions>
                        </Select>
                    </FormItem>

                    <FormItem Label="原生插件列表" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select Mode="multiple"
                                @bind-Values="funIds"
                                Placeholder="选择原生插件, 选择后会开启自动调用"
                                TItemValue="string"
                                TItem="string"
                                Size="@AntSizeLDSType.Default">
                            <SelectOptions>
                                @foreach (var fun in _funList)
                                {
                                    <SelectOption TItem="string" TItemValue="string" Value="@fun.Key" Label="@(fun.Key+"-"+fun.Value)" />
                                }
                            </SelectOptions>
                        </Select>
                    </FormItem>
                }
                @if (@context.Type == AppType.kms.ToString())
                {
                    <FormItem Label="知识库" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select Mode="multiple"
                                @bind-Values="kmsIds"
                                Placeholder="选择知识库"
                                TItemValue="string"
                                TItem="string"
                                Size="@AntSizeLDSType.Default">
                            <SelectOptions>
                                @foreach (var kms in _kmsList)
                                {
                                    <SelectOption TItem="string" TItemValue="string" Value="@kms.Id" Label="@kms.Name" />
                                }
                            </SelectOptions>
                        </Select>
                        <Button Type="@ButtonType.Link" OnClick="NavigateKmsList">去创建</Button>
                    </FormItem>
                    <FormItem Label="Rerank重排模型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Select DataSource="@_rerankList"
                                @bind-Value="@context.RerankModelID"
                                ValueProperty="c=>c.Id"
                                LabelProperty="c=>'【'+c.AIType.ToString()+'】'+c.ModelDescription">
                        </Select>
                        <Button Type="@ButtonType.Link" OnClick="NavigateModelList">去创建</Button>
                    </FormItem>
                    <FormItem Label="Rerank数" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <AntDesign.InputNumber @bind-Value="context.RerankCount" PlaceHolder="Rerank数"></AntDesign.InputNumber>
                    </FormItem>
                    <FormItem Label="提问最大token数" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <AntDesign.InputNumber @bind-Value="context.MaxAskPromptSize" PlaceHolder="提问最大token数"></AntDesign.InputNumber>
                    </FormItem>              
                    <FormItem Label="回答最大token数" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <AntDesign.InputNumber @bind-Value="context.AnswerTokens" PlaceHolder="回答最大token数"></AntDesign.InputNumber>
                    </FormItem>
                    <FormItem Label="向量匹配数" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <AntDesign.InputNumber @bind-Value="context.MaxMatchesCount" PlaceHolder="向量匹配数"></AntDesign.InputNumber>
                    </FormItem>
                    <FormItem Label="最低相似度（%）" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <Slider TValue="double" Style="display: inline-block;width: 300px; " Min="0" Max="100" DefaultValue="70" @bind-Value="@context.Relevance" />
                    </FormItem>
                }
                <FormItem Label=" " Style="margin-top:32px" WrapperCol="LayoutModel._submitFormLayout.WrapperCol">
                    <Button Type="primary" HtmlType="submit">
                        保存
                    </Button>
                    <Button OnClick="Back">
                        返回
                    </Button>
                </FormItem>
            </Form>
        </Card>
    </ChildContent>
</PageContainer>


<style>
    .avatar-uploader > .ant-upload {
        width: 128px;
        height: 128px;
    }
</style>